package com.leyou.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.dto.BrandDTO;
import com.leyou.mapper.CategoryBrandMapper;
import com.leyou.mapper.CategoryMapper;
import com.leyou.pojo.Brand;
import com.leyou.pojo.Category;
import com.leyou.pojo.CategoryBrand;
import com.leyou.service.CategoryBrandService;
import com.leyou.service.CategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-12-09 17:21
 */
@Service
public class CategoryBrandServiceImpl extends ServiceImpl<CategoryBrandMapper, CategoryBrand> implements CategoryBrandService {
    /**
     * 根据分类id查询品牌信息
     * @param id
     * @return
     */
    @Override
    public List<Long> queryBrandId(Long id) {
        return this.baseMapper.queryBrandId(id);
    }

    /**
     * 添加品牌信息
     * @param brandDTO
     * @param brand
     */
    @Transactional
    @Override
    public void add(BrandDTO brandDTO, Brand brand) {
        List<Long> categoryIds = brandDTO.getCategoryIds();
        Long id = brand.getId();
        for (Long categoryId : categoryIds) {
            this.baseMapper.add(id,categoryId);
        }
    }

    /**
     * 删除中间表
     * @param id
     */
    @Override
    public void removeByBrandId(Long id) {
        this.baseMapper.deleteByBrandId(id);
    }

}
